//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_BSP_MMU_H__
#define __ELASTOS_BSP_MMU_H__

#define KERNEL_PHYSBASE             ((physaddr_t)0xa0000000)
#define KERNEL_IMAGEPHYSBASE        ((physaddr_t)0xa0020000)
#define KERNEL_MEMMAPPEDIOBASE      ((physaddr_t)0x40000000)
#define KERNEL_MEMMAPPEDIOLIMIT     ((physaddr_t)0x58000000)

#define PHYSADDR(va) \
    ((physaddr_t)(va) - (offset_t)krn.vaKernelVirtBase + \
     (offset_t)KERNEL_PHYSBASE)

#define VIRTADDR(pa) \
    ((virtaddr_t)((pa) - KERNEL_PHYSBASE + (offset_t)krn.vaKernelVirtBase))

// in virtual address
#define PAGE_SHIFT                  (12)
#define PAGEDIR_SHIFT               (20)

#define PAGE_SIZE                   (1u << PAGE_SHIFT)

#define NUMBEROF_PAGES(size)        ((size) >> PAGE_SHIFT)
#define PHYSADDR_TO_PAGENO(pa)      ((pa) >> PAGE_SHIFT)
#define VIRTADDR_TO_PAGENO(va)      PHYSADDR_TO_PAGENO(PHYSADDR(va))
#define PAGENO_TO_PHYSADDR(no)      ((no) << PAGE_SHIFT)
#define PAGENO_TO_VIRTADDR(no)      VIRTADDR(PAGENO_TO_PHYSADDR(no))

const uint_t c_uMaxNumberOfPages    = NUMBEROF_PAGES(0xffffffff) + 1;

const uint_t c_uKernelBasePageNo    =
        PHYSADDR_TO_PAGENO((physaddr_t)krn.vaKernelVirtBase);

const uint_t c_uNumberOfKernelPages =
        c_uMaxNumberOfPages - c_uKernelBasePageNo;

#endif //__ELASTOS_BSP_MMU_H__
